<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<input type="hidden" id="equipment_id" value="${obj.equipment_id}"/>
<textarea class="layui-textarea" id="text_content" style="display: none">  
</textarea>
<div class="site-demo-button" style="margin-top: 20px; text-align:right; padding-right:20px" >
  <button class="layui-btn site-demo-layedit" data-type="content">保存</button>
</div>
<script>
$(function(){
	initLayedit($.trim($("#equipment_id").val()));
});

function initLayedit(equipment_id){
	   $.ajax({
		   url:base+"/dataCenter/businessdata/findEquipmentProperty",
		   data:{equipment_id:equipment_id},
		   async: false,
		   success:function(data,status){
			   $("#text_content").text(data.equipment_property);
		   }
	   });
}

layui.use('layedit', function(){
	  var layedit = layui.layedit,$ = layui.jquery;
	  layedit.set({
	      uploadImage: {
	          url: base+'/datacenter/common/uploadFile',//url
	          type: 'post'
	      }
	  })
	  //构建一个默认的编辑器
	  var index = layedit.build('text_content',{
		    height: 500
	  })
	  //编辑器外部操作
	  var active = {
	    content: function(){
	      var equipment_data = layedit.getContent(index);
		  $.post(base+"/dataCenter/businessdata/updateEquipmentProperty",{
				equipment_id:$.trim($("#equipment_id").val()),
				equipment_data:equipment_data
		  },function (data,status){
				if(data!=""&&data!=null){
					if(data.statusCode == 0){
						layer.msg('更新成功', {icon: 1,time:2000});
					}else{
						layer.msg(data.message, {icon: 2,time:2000});
					}
				}else{
					layer.msg('更新失败!', {icon: 2,time:2000});
				}
				setTimeout(function(){
					layer.closeAll()
				},1000); 
	  	 })
	      
	    }
	  };
	  
	  $('.site-demo-layedit').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
	 
	});
</script>
</body>
</html>